package com.hxf.service.menu.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hxf.dto.MealMenuDto;
import com.hxf.dto.MenuDto;
import com.hxf.dto.ReturnData;
import com.hxf.exception.DaoLevelException;
import com.hxf.exception.ServiceException;
import com.hxf.service.base.impl.BaseServiceImpl;
import com.hxf.service.menu.MenuService;
import com.hxf.web.vo.MenuVo;
import com.hxf.web.vo.OrderDetailVo;

/**
 * service菜单管理业务类
 * @author tengyicheng
 * @version [1.0, 2013/09/22]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Repository("menuService")
public class MenuServiceImpl extends BaseServiceImpl implements MenuService {

	@Override
	public List<MenuDto> findByMenu(MenuDto menuDto)throws ServiceException {
		try {
			return super.daoFacade.getMenuDao().findByMenu(menuDto);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		}
	}
	
	@Override
	public ReturnData<MenuDto> findByMenu(MenuVo menuDto, int targetPage,
			int pageSize) throws ServiceException {
		try {
			return super.daoFacade.getMenuDao().findByMenu(menuDto, targetPage, pageSize);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		}
	}
	
	@Override
	public void updateMenu(MenuDto menu) throws ServiceException {  
		MenuDto menuDto = (MenuDto) super.get(MenuDto.class, menu.getMenuId());
		menuDto.setMenuName(menu.getMenuName());
		menuDto.setMenuUrl(menu.getMenuUrl());
		menuDto.setMenuOrder(menu.getMenuOrder());
		menuDto.setStatus(menu.getStatus());
		menuDto.setModifyDate(menu.getModifyDate()); 
		menuDto.setModifyUser(menu.getModifyUser());
		menuDto.setParentId(menu.getParentId());
		super.update(menuDto);
		
	}

	@Override
	public List<MenuDto> findMenuTree(Integer userId) throws ServiceException {
		try {
			return super.daoFacade.getMenuDao().findMenuTree(userId);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		} 
	}

	@Override
	public List<OrderDetailVo> findByMealMenuPreferential(MealMenuDto mealMenuDto) throws ServiceException { 
		try {
			return super.daoFacade.getMealMenuDao().findByMealMenuPreferential(mealMenuDto);
		} catch (DaoLevelException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public List<MenuDto> RestaurentfindMenuTree(Integer userId)
			throws ServiceException {
		try {
			return super.daoFacade.getMenuDao().RestaurentfindMenuTree(userId);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		} 
	}
}
